package com.erp.ae.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.ruoyi.ae.api.domain.AeHandoverCommitInfo;
import com.erp.ae.domain.AeLogisticsSellerAddress;
import com.ruoyi.ae.api.domain.AeStoreOrderReceiptAddress;
import com.ruoyi.ae.api.domain.AeWarehouseOrderInfo;
import com.erp.ae.domain.dto.AeLogisticsOrderDetailDto;
import com.ruoyi.ae.api.domain.dto.DeclareProductDTOS;
import com.ruoyi.ae.api.domain.dto.OrderShipmentForTopDto;
import com.erp.ae.domain.enums.AliExpressInterfaceEnum;
import com.erp.ae.mapper.AeWarehouseOrderInfoMapper;
import com.erp.ae.service.IAeLogisticsService;
import com.erp.ae.service.IAeStoreOrderReceiptAddressService;
import com.erp.ae.service.IAeWarehouseOrderInfoService;
import com.erp.ae.utils.AeApiUtils;
import com.global.iop.domain.Protocol;
import com.ruoyi.common.core.domain.R;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.*;

/**
 * 商户订单Service业务层处理
 *
 * @author erp
 * @date 2023-03-09
 */
@RequiredArgsConstructor
@Service
public class IAeLogisticsServiceImpl implements IAeLogisticsService {
    @Resource
    RestTemplate restTemplate;
    private final IAeStoreOrderReceiptAddressService iAeStoreOrderReceiptAddressService;
    private final IAeWarehouseOrderInfoService iAeWarehouseOrderInfoService;
    private final AeWarehouseOrderInfoMapper aeWarehouseOrderInfoMapper;


    @Override
    public R<Object> createWarehouseOrder(Map<String, Object> map, String accessToken) {
        Long orderId = (Long) map.get("orderId");
        //获取订单的服务地址
//        ErpSellerOrder erpSellerOrder = iErpSellerOrderService.selectByOrderId(orderId);

        String warehouseCarrierService = (String) map.get("warehouseCarrierService");
        //获取该订单的收货人地址Id
        AeStoreOrderReceiptAddress address = iAeStoreOrderReceiptAddressService.selectAddressByOrderId(orderId);
        if (address == null) {
            return R.fail("没有买家收货地址");
        }
        Map<String, Object> paremeterMap = new HashMap<>();


        String apiName = "";
        String returnMsg = "";

        //获取卖家地址
        Long refundAddressId = 0L;
        Long pickupAddressId = 0L;
        Long senderAddressId = 0L;
        Map<String, Long> addressMap = getStoreAddress(accessToken, refundAddressId, pickupAddressId, senderAddressId);
        refundAddressId = addressMap.get("refundAddressId");
        pickupAddressId = addressMap.get("pickupAddressId");
        senderAddressId = addressMap.get("senderAddressId");
        if ((refundAddressId == 0L)) {
            return R.fail("该店铺没有设置退货地址为深圳仓");
        }
        if ((pickupAddressId == 0L)) {
            return R.fail("该店铺没有设置打包地址为深圳仓");
        }
        if ((senderAddressId == 0L)) {
            return R.fail("该店铺没有设置发货地址为深圳仓");
        }
        paremeterMap = new HashMap<>();
//        发货方式：上门揽收DOOR_PICKUP, 自寄SELF_POST, 自送SELF_SEND
        String pickupType = "DOOR_PICKUP";
        //订单来源
        String tradeOrderFrom = "ESCROW";
        //declare_product_d_t_os 之下
        List<DeclareProductDTOS> declareProductDTOSList = (List<DeclareProductDTOS>) map.get("declareProductDTOSList");

        String detailAddress = address.getDetailAddress();

        String replacedString = detailAddress.replace("\"", "'");


        paremeterMap.put("address_d_t_os",
                "{ \"receiver\":{\n" +
//                        "\"member_type\":\"\\u7C7B\\u578B\"," +
                        "\"country\":\"" + address.getCountry() + "\"," +
                        "\"city\":\"" + address.getCity() + "\"," +
                        "\"county\":\"" + address.getPhoneCountry() + "\"," +
                        "\"mobile\":\"" + address.getMobileNo() + "\"," +
//                        "\"trademanage_id\":\"cn234234234\"," +
                        "\"province\":\"" + address.getProvince() + "\"," +
//                        "\"phone\":\"" + address.getPhoneNumber() + "\"," +
                        "\"post_code\":\"" + address.getZip() + "\"," +
                        "\"name\":\"" + address.getContactPerson() + "\"," +
//                        "\"fax\":\"" + address.getFaxNumber() + "\"," +
                        "\"street_address\":\"" + address.getDetailAddress() + "\"},"
                        + "\"pickup\":{" + "\"address_id\":\"" + pickupAddressId + "\"},"
                        + "\"sender\":{" + "\"address_id\":\"" + senderAddressId + "\"},"
                        + "\"refund\":{" + "\"address_id\":\"" + refundAddressId + "\"}"
                        + "}"
        );
        paremeterMap.put("pickup_type", pickupType);
        paremeterMap.put("oaid", address.getOaid());

        paremeterMap.put("trade_order_from", tradeOrderFrom);
        paremeterMap.put("warehouse_carrier_service", warehouseCarrierService);
        paremeterMap.put("trade_order_id", orderId);
        paremeterMap.put("declare_product_d_t_os", JSON.toJSONString(declareProductDTOSList));
        returnMsg =
                AeApiUtils.sendRequest(
                        AliExpressInterfaceEnum.createLogisticsOrder.getCode(),
                        paremeterMap,
                        Protocol.TOP,
                        accessToken
                );
        System.out.println(returnMsg);
        //解析数据
        if (!returnMsg.contains("aliexpress_logistics_order_createorder_response") || returnMsg.contains("error_desc")) {
            //获取失败
            return R.fail(returnMsg);
        } else {
            JSONObject result = JSONObject.parseObject(returnMsg).getJSONObject("aliexpress_logistics_order_createorder_response").getJSONObject("result");
            //查找是否已经有了线上物流单
            for (Object declareProductFor : declareProductDTOSList) {
                String jsonObject = JSON.toJSONString(declareProductFor);
                DeclareProductDTOS declareProductDTOS = JSONObject.parseObject(jsonObject, DeclareProductDTOS.class);

                AeWarehouseOrderInfo aeWarehouseOrderInfo = aeWarehouseOrderInfoMapper.selectOne(
                        new LambdaQueryWrapper<AeWarehouseOrderInfo>().eq(AeWarehouseOrderInfo::getChildOrderId, Long.valueOf(declareProductDTOS.getChild_order_id()))
                );
                AeWarehouseOrderInfo newWarehouseOrderInfo = new AeWarehouseOrderInfo();
                if (aeWarehouseOrderInfo != null) {
                    newWarehouseOrderInfo.setId(aeWarehouseOrderInfo.getId());
                }
                newWarehouseOrderInfo.setSellerId((String) map.get("sellerId"));
                newWarehouseOrderInfo.setTradeOrderId(orderId);
                // out_order_code LP单号
                newWarehouseOrderInfo.setOutOrderCode(result.getString("out_order_code"));
                //intl_tracking_no  国际运单号
                newWarehouseOrderInfo.setIntlTrackingNo(result.getString("intl_tracking_no"));
                //out_order_id  外部订单号
                newWarehouseOrderInfo.setOutOrderId(result.getString("out_order_id"));
                //warehouse_order_id  物流订单号
                newWarehouseOrderInfo.setWarehouseOrderId(result.getString("warehouse_order_id"));
                //物流编码
                newWarehouseOrderInfo.setWarehouseCarrierService(warehouseCarrierService);
                //卖家三地址
                newWarehouseOrderInfo.setSenderAddressId(senderAddressId);
                newWarehouseOrderInfo.setReceiverAddressId(refundAddressId);
                newWarehouseOrderInfo.setPickupAddressId(pickupAddressId);
                newWarehouseOrderInfo.setXxjobFlag(0);
                //将信息存入线上发货表
                newWarehouseOrderInfo.setChildOrderId(Long.valueOf(declareProductDTOS.getChild_order_id()));
                newWarehouseOrderInfo.setCategoryCnDesc(declareProductDTOS.getCategory_cn_desc());
                newWarehouseOrderInfo.setCategoryEnDesc(declareProductDTOS.getCategory_en_desc());
                newWarehouseOrderInfo.setContainsBattery(declareProductDTOS.getContains_battery());
                newWarehouseOrderInfo.setBreakable(declareProductDTOS.getBreakable());
                newWarehouseOrderInfo.setAneroidMarkup(declareProductDTOS.getAneroid_markup());
                newWarehouseOrderInfo.setOnlyBattery(declareProductDTOS.getOnly_battery());
                newWarehouseOrderInfo.setContainsSpecialGoods(declareProductDTOS.getContains_special_goods());
                newWarehouseOrderInfo.setProductDeclareAmount(declareProductDTOS.getProduct_declare_amount());
                newWarehouseOrderInfo.setProductId(declareProductDTOS.getProduct_id());
                newWarehouseOrderInfo.setProductNum(declareProductDTOS.getProduct_num());
                newWarehouseOrderInfo.setProductWeight(declareProductDTOS.getProduct_weight());
                newWarehouseOrderInfo.setSkuCode(declareProductDTOS.getSku_code());
                newWarehouseOrderInfo.setSkuValue(declareProductDTOS.getSku_value());
                //TYPE = 1
                newWarehouseOrderInfo.setType(1);
                aeWarehouseOrderInfoMapper.insertOrUpdate(newWarehouseOrderInfo);
            }
            return R.ok("线上发货成功，正在获取国际面单，请稍后");
        }
    }

    private Map<String, Long> getStoreAddress(String accessToken,
                                              Long refundAddressId,
                                              Long pickupAddressId,
                                              Long senderAddressId) {
        Map<String, Long> map = new HashMap<>();
        //获取卖家地址
        String returnMsg =
                AeApiUtils.sendRequest(
                        AliExpressInterfaceEnum.queryByProduct.getCode(),
                        "seller_address_query",
                        "pickup,sender,refund",
                        Protocol.TOP,
                        accessToken
                );
        System.out.println(returnMsg);
        //获取三者信息
        //将数据解析，拿到对应的地址
//        String defaultAddress = configService.selectConfigByKey("ae.productPost.defaultAddress");
//        System.out.println("defaultAddress地址:" + defaultAddress);
//        String enDefaultAddress = configService.selectConfigByKey("ae.productPost.enDefaultAddress");
//        System.out.println("enDefaultAddress地址:" + enDefaultAddress);

        String defaultAddress = "工业园骏捷云仓宿舍楼";
        String enDefaultAddress = "Junjie Yuncang Dormitory Building";

        List<AeLogisticsSellerAddress> refundList = JSONObject.parseObject(returnMsg)
                .getJSONObject("aliexpress_logistics_redefining_getlogisticsselleraddresses_response")
                .getJSONObject("refund_seller_address_list")
                .getJSONArray("refundselleraddresslist").toJavaList(AeLogisticsSellerAddress.class);
        List<AeLogisticsSellerAddress> pickupList = JSONObject.parseObject(returnMsg)
                .getJSONObject("aliexpress_logistics_redefining_getlogisticsselleraddresses_response")
                .getJSONObject("pickup_seller_address_list")
                .getJSONArray("pickupselleraddresslist").toJavaList(AeLogisticsSellerAddress.class);
        List<AeLogisticsSellerAddress> senderList = JSONObject.parseObject(returnMsg)
                .getJSONObject("aliexpress_logistics_redefining_getlogisticsselleraddresses_response")
                .getJSONObject("sender_seller_address_list")
                .getJSONArray("senderselleraddresslist").toJavaList(AeLogisticsSellerAddress.class);
        for (AeLogisticsSellerAddress aeLogisticsSellerAddress : refundList) {
            System.out.println("退货地址:" + aeLogisticsSellerAddress.getStreet_address());
            if (aeLogisticsSellerAddress.getStreet_address().contains(defaultAddress)) {
                System.out.println("退货地址匹配成功");
                refundAddressId = aeLogisticsSellerAddress.getAddress_id();
            }
        }
        for (AeLogisticsSellerAddress aeLogisticsSellerAddress : pickupList) {
            System.out.println("揽收地址:" + aeLogisticsSellerAddress.getStreet_address());
            if (aeLogisticsSellerAddress.getStreet_address().contains(defaultAddress)) {
                System.out.println("揽收地址匹配成功");
                pickupAddressId = aeLogisticsSellerAddress.getAddress_id();
            }
        }
        for (AeLogisticsSellerAddress aeLogisticsSellerAddress : senderList) {
            System.out.println("发货地址:" + aeLogisticsSellerAddress.getStreet_address());
            if (aeLogisticsSellerAddress.getStreet_address().contains(enDefaultAddress) || aeLogisticsSellerAddress.getStreet_address().equals(enDefaultAddress)) {
                System.out.println("发货地址匹配成功");
                senderAddressId = aeLogisticsSellerAddress.getAddress_id();
            }
        }
        map.put("refundAddressId", refundAddressId);
        map.put("pickupAddressId", pickupAddressId);
        map.put("senderAddressId", senderAddressId);
        return map;
    }


    @Override
    public R<Object> synchronizationWarehouseOrder(Map<String, Object> map) {
        String accessToken = AeApiUtils.getToken((String) map.get("sellerId"));
        if (ObjectUtils.isNull(accessToken)) {
            return R.fail("accessToken不存在或已过期");
        }
        Long orderId = (Long) map.get("orderId");
        //获取订单的服务地址
//        ErpSellerOrder erpSellerOrder = iErpSellerOrderService.selectByOrderId(orderId);

        String warehouseCarrierService = (String) map.get("warehouseCarrierService");
        //获取该订单的收货人地址Id
        AeStoreOrderReceiptAddress address = iAeStoreOrderReceiptAddressService.selectAddressByOrderId(orderId);
        if (address == null) {
            return R.fail("没有买家收货地址");
        }
        Map<String, Object> paremeterMap = new HashMap<>();


        //获取卖家地址
        Long refundAddressId = 0L;
        Long pickupAddressId = 0L;
        Long senderAddressId = 0L;
        Map<String, Long> addressMap = getStoreAddress(accessToken, refundAddressId, pickupAddressId, senderAddressId);
        refundAddressId = addressMap.get("refundAddressId");
        pickupAddressId = addressMap.get("pickupAddressId");
        senderAddressId = addressMap.get("senderAddressId");
        if ((refundAddressId == 0L)) {
            return R.fail("该店铺没有设置退货地址为深圳仓");
        }
        if ((pickupAddressId == 0L)) {
            return R.fail("该店铺没有设置打包地址为深圳仓");
        }
        if ((senderAddressId == 0L)) {
            return R.fail("该店铺没有设置发货地址为深圳仓");
        }
        //declare_product_d_t_os 之下
        List<DeclareProductDTOS> declareProductDTOSList = (List<DeclareProductDTOS>) map.get("declareProductDTOSList");
        Map<String, Object> sendMap = new HashMap<>();
        map.put("order_id", orderId);
        String returnMsg =
                AeApiUtils.sendRequest(
                        AliExpressInterfaceEnum.getOnLineLogisticsInfo.getCode(),
                        sendMap,
                        Protocol.TOP,
                        accessToken
                );

        System.out.println(returnMsg);
        //解析数据
        if (returnMsg.contains("aliexpress_logistics_redefining_getonlinelogisticsinfo_response")) {
            JSONArray resultArray = JSONArray.parseArray(JSONObject.parseObject(returnMsg)
                    .getJSONObject("aliexpress_logistics_redefining_getonlinelogisticsinfo_response")
                    .getJSONObject("result_list")
                    .getString("result"));
            JSONObject result = (JSONObject) resultArray.get(0);

            //查找是否已经有了线上物流单
            for (Object declareProductFor : declareProductDTOSList) {
                String jsonObject = JSON.toJSONString(declareProductFor);
                DeclareProductDTOS declareProductDTOS = JSONObject.parseObject(jsonObject, DeclareProductDTOS.class);

                AeWarehouseOrderInfo aeWarehouseOrderInfo = aeWarehouseOrderInfoMapper.selectOne(
                        new LambdaQueryWrapper<AeWarehouseOrderInfo>().eq(AeWarehouseOrderInfo::getChildOrderId, Long.valueOf(declareProductDTOS.getChild_order_id()))
                );
                AeWarehouseOrderInfo newWarehouseOrderInfo = new AeWarehouseOrderInfo();
                if (aeWarehouseOrderInfo != null) {
                    newWarehouseOrderInfo.setId(aeWarehouseOrderInfo.getId());
                }
                newWarehouseOrderInfo.setSellerId((String) map.get("sellerId"));
                newWarehouseOrderInfo.setTradeOrderId(orderId);
                // out_order_code LP单号
                newWarehouseOrderInfo.setOutOrderCode(result.getString("lp_number"));
                //intl_tracking_no  国际运单号
                newWarehouseOrderInfo.setIntlTrackingNo(result.getString("internationallogistics_id"));
                //out_order_id  外部订单号
//                newWarehouseOrderInfo.setOutOrderId(result.getString("out_order_id"));
                //warehouse_order_id  物流订单号
                newWarehouseOrderInfo.setWarehouseOrderId(result.getString("online_logistics_id"));
                //物流编码
                newWarehouseOrderInfo.setWarehouseCarrierService(result.getString("international_logistics_type"));
                //卖家三地址
                newWarehouseOrderInfo.setSenderAddressId(senderAddressId);
                newWarehouseOrderInfo.setReceiverAddressId(refundAddressId);
                newWarehouseOrderInfo.setPickupAddressId(pickupAddressId);
                newWarehouseOrderInfo.setXxjobFlag(0);
                //将信息存入线上发货表
                newWarehouseOrderInfo.setChildOrderId(Long.valueOf(declareProductDTOS.getChild_order_id()));
                newWarehouseOrderInfo.setCategoryCnDesc(declareProductDTOS.getCategory_cn_desc());
                newWarehouseOrderInfo.setCategoryEnDesc(declareProductDTOS.getCategory_en_desc());
                newWarehouseOrderInfo.setContainsBattery(declareProductDTOS.getContains_battery());
                newWarehouseOrderInfo.setBreakable(declareProductDTOS.getBreakable());
                newWarehouseOrderInfo.setAneroidMarkup(declareProductDTOS.getAneroid_markup());
                newWarehouseOrderInfo.setOnlyBattery(declareProductDTOS.getOnly_battery());
                newWarehouseOrderInfo.setContainsSpecialGoods(declareProductDTOS.getContains_special_goods());
                newWarehouseOrderInfo.setProductDeclareAmount(declareProductDTOS.getProduct_declare_amount());
                newWarehouseOrderInfo.setProductId(declareProductDTOS.getProduct_id());
                newWarehouseOrderInfo.setProductNum(declareProductDTOS.getProduct_num());
                newWarehouseOrderInfo.setProductWeight(declareProductDTOS.getProduct_weight());
                newWarehouseOrderInfo.setSkuCode(declareProductDTOS.getSku_code());
                newWarehouseOrderInfo.setSkuValue(declareProductDTOS.getSku_value());

                //TYPE = 0
                newWarehouseOrderInfo.setType(0);
                aeWarehouseOrderInfoMapper.insertOrUpdate(newWarehouseOrderInfo);
            }
            return R.ok("同步成功，正在获取国际面单，请稍后");
        } else {
            return R.fail("同步失败");
        }

    }

    @Override
    public R<Object> getOrderOnlineLogisticsLabel() {
        //查找数据库里所有线上发货订单中，国际运单号为空的
        List<AeWarehouseOrderInfo> aeWarehouseOrderInfos = iAeWarehouseOrderInfoService.queryLogisticsOrder();
        //循环线上交接单
        for (AeWarehouseOrderInfo orderInfo : aeWarehouseOrderInfos) {
            //获取国际运单号
            String accessToken = new String();
            try {
                accessToken = AeApiUtils.getToken(orderInfo.getSellerId());
            } catch (Exception e) {
                continue;
            }
            Map<String, Object> paremeterMap = new HashMap<>();
            //根据订单id获取用户选择的线上物流模板
            paremeterMap.put("trade_order_id", orderInfo.getTradeOrderId());
            String returnMsg =
                    AeApiUtils.sendRequest(
                            AliExpressInterfaceEnum.queryLogisticsOrderDetail.getCode(),
                            paremeterMap,
                            Protocol.TOP,
                            accessToken
                    );
            System.out.println(returnMsg);
            JSONArray orderList = JSONObject.parseObject(returnMsg)
                    .getJSONObject("aliexpress_logistics_querylogisticsorderdetail_response")
                    .getJSONObject("result")
                    .getJSONObject("result_list")
                    .getJSONArray("aeop_logistics_order_detail_dto");
            if (Objects.isNull(orderList)) {
                orderInfo.setXxjobFlag(orderInfo.getXxjobFlag() + 1);
                iAeWarehouseOrderInfoService.updateAeWarehouseOrderInfo(orderInfo);
                continue;
            }
            //解析详情
            List<AeLogisticsOrderDetailDto> LogisticsOrderList = orderList.toJavaList(AeLogisticsOrderDetailDto.class);
            for (AeLogisticsOrderDetailDto aeLogisticsOrderDetailDto : LogisticsOrderList) {
                //如果不是填写待填写发货通知则不继续进行
                if (!aeLogisticsOrderDetailDto.getLogisticsStatus().equals("wait_pickup_transfer")) {
                    continue;
                }
                //说明已结束
                orderInfo.setXxjobFlag(6);
                orderInfo.setIntlTrackingNo(aeLogisticsOrderDetailDto.getInternationalLogisticsNum());
                //进行查找线上物流面单
                String orderPrintInfo = getOrderPrintInfo(aeLogisticsOrderDetailDto.getInternationalLogisticsNum(), accessToken);
                orderInfo.setOnlineLogisticsLabel(orderPrintInfo);
                orderInfo.setSolutionCode(aeLogisticsOrderDetailDto.getSolutionCode());
                iAeWarehouseOrderInfoService.updateAeWarehouseOrderInfo(orderInfo);
                //待改造为内部接口
                ResponseEntity<String> forEntity = restTemplate
                        .postForEntity("192.168.110.8:8860/ae/purchaseOrder/createErpWarehouseOrder", orderInfo, String.class);

            }

        }

        return R.ok("已完成国际运单号同步");
    }

    @Override
    public R<Object> queryLogisticsOrderDetail(Map<String, Object> map) {
        String accessToken = AeApiUtils.getToken((String) map.get("store_id"));
        if (ObjectUtils.isNull(accessToken)) {
            return R.fail("店铺授权失效");
        }
        //获取卖家地址
        String returnMsg =
                AeApiUtils.sendRequest(
                        AliExpressInterfaceEnum.queryLogisticsOrderDetail.getCode(),
                        map,
                        Protocol.TOP,
                        accessToken
                );
        System.out.println(returnMsg);
        return R.ok(returnMsg);
    }

    private String getOrderPrintInfo(String internationalLogisticsNum, String accessToken) {
        //获取线上物流面单
        Map<String, Object> paremeterMap = new HashMap<>();
        //根据订单id获取用户选择的线上物流模板
        paremeterMap.put("international_logistics_id", internationalLogisticsNum);
        String returnMsg =
                AeApiUtils.sendRequest(
                        AliExpressInterfaceEnum.getPrintInfo.getCode(),
                        paremeterMap,
                        Protocol.TOP,
                        accessToken
                );
        System.out.println(returnMsg);
        String onlineLogisticsLabel = JSONObject.parseObject(returnMsg)
                .getJSONObject("aliexpress_logistics_redefining_getprintinfo_response")
                .getJSONObject("result")
                .getString("body");

        if (onlineLogisticsLabel == null || onlineLogisticsLabel.equals("")) {
            return null;
        }
        return onlineLogisticsLabel;
    }

    @Override
    public R<Object> getPrintInfo(String internationalLogisticsId, Long sellerId) {
        //生成参数Map
        Map<String, Object> paremeterMap = new HashMap<>();
        paremeterMap.put("actual_carrier", internationalLogisticsId);
        //获取店铺的accessToken
        String accessToken = AeApiUtils.getToken(sellerId);
        String returnMsg =
                AeApiUtils.sendRequest(
                        AliExpressInterfaceEnum.getPrintInfo.getCode(),
                        "international_logistics_id",
                        paremeterMap,
                        Protocol.TOP,
                        accessToken
                );
        return R.ok(returnMsg);
    }

    @Override
    public R<Object> getprintinfo(String internationalLogisticsId, String sellerId) {
        String accessToken = AeApiUtils.getToken(sellerId);
        Map<String, Object> paremeterMap = new HashMap<>();
        //根据订单id获取用户选择的线上物流模板
        paremeterMap.put("international_logistics_id", internationalLogisticsId);
        String returnMsg =
                AeApiUtils.sendRequest(
                        AliExpressInterfaceEnum.getPrintInfo.getCode(),
                        paremeterMap,
                        Protocol.TOP,
                        accessToken
                );
        System.out.println(returnMsg);
        return R.ok(returnMsg);
    }

    //TODO 待改造传参类型
    @Override
    public R<Object> logisticsServiceQuery(Map<String, Object> map) {
//        //获取店铺的accessToken
//        String accessToken = AeApiUtils.getToken((String) map.get("sellerId"));
////        String accessToken = accessTokenTest;
//        Map<String, Object> paremeterMap = new HashMap<>();
//        //获取子订单商品的长宽高重量
//        List<ErpCollectProductSkuPackageInfo> skuPackageInfoList = (List<ErpCollectProductSkuPackageInfo>) map.get("skuPackageInfoList");
//        String array = JSON.toJSONString(skuPackageInfoList);
//        //获取包裹的长宽高重量
//        LinkedHashMap linkedHashMap = (LinkedHashMap) map.get("packageInfo");
//
//        String json = new JSONObject().toJSONString(linkedHashMap);
//
//        ErpCollectProductSkuPackageInfo packInfo = new JSONObject().parseObject(json, ErpCollectProductSkuPackageInfo.class);
//        //根据订单id获取用户选择的线上物流模板
//        String apiName = "aliexpress.logistics.service.query";
//        paremeterMap.put("interface_request", "{\"sub_order_list\":" + array + "," +
//                "\"goods_width\":" + packInfo.getGoodsWidth() + "," +
//                "\"goods_height\":" + packInfo.getGoodsHeight() + "," +
//                "\"goods_weight\":\"" + packInfo.getGoodsWeight() + "\"," +
//                "\"goods_length\":" + packInfo.getGoodsLength() + "," +
//                "\"order_id\":\"" + packInfo.getOrderId() + "\"" +
//                "}");
//        String returnMsg = new String();
//        returnMsg =
//                AeApiUtils.sendRequest(
//                        apiName,
//                        paremeterMap,
//                        Protocol.TOP,
//                        accessToken
//                );
//
//        System.out.println(returnMsg);
//        return R.ok(returnMsg);
        return R.fail("待改造传参类型");
    }

    @Override
    public R<Object> sellerShipmentForTop(OrderShipmentForTopDto orderShipmentForTopDto) {
        //生成参数Map
        Map<String, Object> paremeterMap = new HashMap<>();
        //获取店铺的accessToken
        String accessToken = AeApiUtils.getToken(orderShipmentForTopDto.getSeller_id());
        paremeterMap.put("param_aeop_seller_shipment_sub_trade_order_request", JSON.toJSONString(orderShipmentForTopDto));
        String returnMsg =
                AeApiUtils.sendRequest(
                        AliExpressInterfaceEnum.orderShipment.getCode(),
                        paremeterMap,
                        Protocol.TOP,
                        accessToken
                );
        System.out.println(returnMsg);

        if (returnMsg.contains("true")) {
            //存入AE物流声明表中
            return R.ok(returnMsg);
        } else {
            String msg = JSONObject.parseObject(returnMsg)
                    .getJSONObject("aliexpress_logistics_order_shipment_response")
                    .getJSONObject("result")
                    .getString("error_msg");
            return R.fail(msg);
        }
    }

    @Override
    public R<Object> queryLogisticsOrderDetailTwo(Long tradeOrderId, String sellerId) {
        String accessToken = AeApiUtils.getToken(sellerId);
        Map<String, Object> paremeterMap = new HashMap<>();
        //根据订单id获取用户选择的线上物流模板
        paremeterMap.put("trade_order_id", tradeOrderId);
        String returnMsg =
                AeApiUtils.sendRequest(
                        AliExpressInterfaceEnum.queryLogisticsOrderDetail.getCode(),
                        paremeterMap,
                        Protocol.TOP,
                        accessToken
                );
        System.out.println(returnMsg);
        return R.ok(returnMsg);
    }

    @Override
    public R<Object> getStoreAddress(String sellerId) {
        String accessToken = AeApiUtils.getToken(sellerId);
        Map<String, String> map = new HashMap<>();
        //获取卖家地址
        String returnMsg =
                AeApiUtils.sendRequest(
                        AliExpressInterfaceEnum.getLogisticsSellerAddresses.getCode(),
                        "seller_address_query",
                        "pickup,sender,refund",
                        Protocol.TOP,
                        accessToken
                );
        System.out.println(returnMsg);
        //获取三者信息
        //将数据解析，拿到对应的地址

        return R.ok(returnMsg);
    }

    @Override
    public R<Object> handoverCommit(AeHandoverCommitInfo handoverCommitInfo) {
        String accessToken = AeApiUtils.getToken(handoverCommitInfo.getSellerId());
        Map<String, Object> map = new HashMap<>();
        Object userInfo = JSONObject.toJSON(handoverCommitInfo.getUser_info());
        Object pickUpInfo = JSONObject.toJSON(handoverCommitInfo.getPickup_info());
        Object orderList = JSONObject.toJSON(handoverCommitInfo.getSeller_parcel_order_list());
        map.put("seller_parcel_order_list", orderList);
//        map.put("remark", handoverCommitInfo.getRemark());
        map.put("user_info", userInfo);
        map.put("pickup_info", pickUpInfo);
        map.put("locale", handoverCommitInfo.getLocale());
        map.put("type", handoverCommitInfo.getType());
        map.put("client", handoverCommitInfo.getClient());

        //获取卖家地址
        String returnMsg =
                AeApiUtils.sendRequest(
                        AliExpressInterfaceEnum.delPromotionProduct.getCode(),
                        map,
                        Protocol.TOP,
                        accessToken
                );
        System.out.println(returnMsg);
        if (returnMsg.contains("error_response")) {
            return R.fail(returnMsg);
        } else {
            return R.ok(returnMsg);
        }
    }

    @Override
    public R<Object> getHandoverPdf(Map<String, Object> map) {
        String accessToken = AeApiUtils.getToken((String) map.get("sellerId"));
        //获取卖家地址
        String returnMsg =
                AeApiUtils.sendRequest(
                        AliExpressInterfaceEnum.delPromotionProduct.getCode(),
                        map,
                        Protocol.TOP,
                        accessToken
                );
        System.out.println(returnMsg);
        return R.ok(returnMsg);
    }

    @Override
    public R<Object> handoverContentQuery(Map<String, Object> map) {
        String accessToken = AeApiUtils.getToken((String) map.get("sellerId"));
        System.out.println(map);
        //获取卖家地址
        String returnMsg =
                AeApiUtils.sendRequest(
                        AliExpressInterfaceEnum.queryHandoverContent.getCode(),
                        map,
                        Protocol.TOP,
                        accessToken
                );
        System.out.println(returnMsg);

        return R.ok(returnMsg);
    }

    @Override
    public R<Object> getOnlineLogisticsInfo(Map<String, Object> map) {
        String accessToken = AeApiUtils.getToken((String) map.get("store_id"));
        //获取卖家地址
        String returnMsg =
                AeApiUtils.sendRequest(
                        AliExpressInterfaceEnum.getOnLineLogisticsInfo.getCode(),
                        map,
                        Protocol.TOP,
                        accessToken
                );
        System.out.println(returnMsg);
        if (returnMsg.contains("aliexpress_logistics_redefining_getonlinelogisticsinfo_response")) {
            return R.ok(returnMsg);
        } else {
            return R.fail(returnMsg);
        }
    }


}
